/**
 * Created by Withdrawn on 2015/9/25 0025.
 */
//jquery取得url参数
(function ($) {
    $.getUrlParam = function (name) {
        var urlReg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(urlReg);
        if (r != null) return unescape(r[2]); return null;
    }
})(jQuery);

function setCookie(cookiename, cookievalue, hours) {
    var date = new Date();
    date.setTime(date.getTime() + Number(hours) * 3600 * 1000);
    document.cookie = cookiename + "=" + cookievalue + "; path=/;expires ="+date.toGMTString();

    var oDate = new Date();
    oDate.setYear(oDate.getFullYear()+1);
    var sCookie = sName.escape() + '=' + escape(sValue) + ';expires=' + oDate.toGMTString() + ';path=/';
    document.cookie= sCookie;

}

function getcookie(name){
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null){
        return (arr[2]);
    }else{
        return "";
    }
}

function getUserId(){
    var storage = window.localStorage;
    var userid=storage.getItem("userid");
    console.log(userid);
    //if(!userid){
    //  location.href='denglu.html';
    //  return;
    //}




//    if(!userid){
//    alert("执行")
//        $.jsonp({
//            url: 'http://dm.wjbb.com.cn:8080/api/user/main',
//            data: {},
//            callbackParameter: "callback",
//            success: function (data, textStatus, xOptions) {
//                if(data.code==-1){
//                    location.href='denglu.html'
//                }else{
//                    //setCookie("userid",data.id);
//                    storage.setItem("userid",data.id);
//                    userid=data.id;
//                }
//            },
//            error: function (xOptions,textStatus) {
//            }
//        });
//    }

    return userid;
}

function jumptoLogin(url,jumptourl){

    var storage = window.localStorage;
    var userid=storage.getItem("userid");
    storage.setItem("jumpurl",jumptourl);
    if(!userid){
        location.href='denglu.html';
        return;
    }

    location.href = url;
}


var backurl = "";
function jumpbyback(type,url){
  if(type == 0){
    closeApp();
  }else if(type == 1){
    location.href = "tongyou.html";
  }else if(type == 2){
    location.href = "huace.html";
  }else if(type == 3){
    location.href = url;
  }

}


function clearStorage(){
   localStorage.clear();
   //var storage = window.localStorage;
   //storage.removeItem("userid");//清除c的值
}

function getUrl(){
    var url="dm.wjbb.com.cn:8080";
    return url;
}

function getPicurl(){
    var url="http://dmimg.wjbb.com.cn:8080";
    return url;
}

function getLoc(){
    var storage = window.localStorage;
    var lat = storage.getItem("lat");
    var lng = storage.getItem("lng");
    return {lat:lat,lng:lng};

}

var BASE_IMAGEURL = "http://dmimg.wjbb.com.cn:8080";
function getPics(){
    var imgs=$("#ul img");
    var paths=[];
    $.each(imgs,function(index,ele){
        if(index != 0 && index != imgs.length - 1){
             var pic = $(ele).attr('src').replace(BASE_IMAGEURL,"");
             paths.push(pic);
        }
    })
    var paths=paths.join(",");
    return paths;
}

var messagingIframe;
messagingIframe = document.createElement('iframe');
messagingIframe.style.display = 'none';
document.documentElement.appendChild(messagingIframe);

function easeMobGoChat(mobile){
    var storage = window.localStorage;
    var phonenumber = storage.getItem("phonenum");
    messagingIframe.src = "/ios/easeMob/goChat?username="+mobile+"&phonenumber="+phonenumber;
}

function easeMobLogin(){
    var phonenum=$("#phonenum").val();
    messagingIframe.src = "/ios/easeMob/login?name="+phonenum;
}

function easeMobLogout(){
    var storage = window.localStorage;
    var phonenumber = storage.getItem("phonenum");
    messagingIframe.src = "/ios/easeMob/Logout?phonenumber="+phonenumber;
}

function publicImage_huace(){
    messagingIframe.src = "/ios/pubImage_huace";
}

function publicImage(){
    messagingIframe.src = "/ios/pubImage";
}

function publicImage_user(){
    messagingIframe.src = "/ios/pubImage_user";
}

function goChatList(){
    var storage = window.localStorage;
    var phonenum = storage.getItem("phonenum");
    messagingIframe.src = "/ios/easeMob/chatList?phonenumber="+phonenum;
}

function goPay(orderid){
    messagingIframe.src = "/ios/pay?orderId="+orderid;
}


function getLocation_xianlu(){
    messagingIframe.src = "/ios/location_xianlu";
}

function getLocation_xianlubox(){
    messagingIframe.src = "/ios/location_xianlubox";
}

function getLocation_denglu(){
    messagingIframe.src = "/ios/location_denglu";
}


function showCount(unreadCount){
    var storage = window.localStorage;
    storage.setItem("unreadCount",unreadCount);
}

function showToast(msg){
    alert(msg);
}

function shareUmeng(content,pic){
    messagingIframe.src = "/ios/share";
}

//function loadImage(flag,folder){
//    if(folder == "photoBook"){
//        publicImage_huace();
//    }else if (folder == "sameway"){
//        publicImage_user();
//    }else if (folder == "user"){
//        publicImage();
//    }
//}

